/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GameManager;

import PacketHandling.PacketHandler;
import horizon.component.IUpdate;
import horizon.entity.Entity;
import horizon.entity.Player;
import horizon.map.MapGenerator;
import horizon.space.Planet;
import horizon.util.Vector2;
import java.util.ArrayList;

/**
 *
 * @author Student
 */
public class Universe implements IUpdate {

    ArrayList<Planet> planets = new ArrayList<Planet>();
    private static Universe instance;

    public static Universe getInstance() {
        return instance;
    }

    public Universe() {
        planets.add(new Planet(MapGenerator.getMap(0), new Vector2(0, 0), "Earth"));

        instance = this;
    }

    public void addPlayer(Player p, String location) {

        planets.get(0).getM().addEntity(p);
        

    }

    public Entity getEntity(String s) {

        for (Planet p : planets) {

            return p.getEntity(s);

        }

        return null;

    }

    @Override
    public void update(long elapsedTime) {

        for (Planet p : planets) {

            p.update(elapsedTime);

        }

    }

    public String getLocation(String s) {

        for (Planet planet : planets) {

            if (planet.hasEntity(s)) {

                return planet.getId();

            }

        }
        
        return null;
    }
    
    public Planet getPlanet(String s){
        
        
        for (Planet planet : planets) {
            
            if(planet.getId().equals(s)){
                
                return planet;
                
            }
            
        }
        
        return null;
        
    }
    
    
}
